<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>JQuery Validation Engine</title>
	<link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css"/>
	<link rel="stylesheet" href="../css/template.css" type="text/css"/>
	<script src="../js/jquery-1.6.min.js" type="text/javascript">
	</script>
	<script src="../js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8">
	</script>
	<script src="../js/jquery.validationEngine.js" type="text/javascript" charset="utf-8">
	</script>
	<script>
            
		// This method is called right before the ajax form validation request
		// it is typically used to setup some visuals ("Please wait...");
		// you may return a false to stop the request 
		function beforeCall(form, options){
			if (window.console) 
			console.log("Right before the AJAX form validation call");
			return true;
		}
            
		// Called once the server replies to the ajax form validation request
		function ajaxValidationCallback(status, form, json, options){
			if (window.console) 
			console.log(status);
                
			if (status === true) {
				alert("the form is valid!");
				// uncomment these lines to submit the form to form.action
				// form.validationEngine('detach');
				// form.submit();
				// or you may use AJAX again to submit the data
			}
		}
            
		jQuery(document).ready(function(){
			jQuery("#formID").validationEngine({
				ajaxFormValidation: true,
				onAjaxFormComplete: ajaxValidationCallback,
			});
		});
	</script>
</head>
<body>  
	<p style="color:red; text-align:center">Please run this demo from a WebServer, it will fail otherwise.
	</p>
	<p>
		This demonstrations shows the use of Ajax <b>form</b>
		and <b>field</b>
		validations.
		<br/>
		The form validation implements callback hooks, so please check the javascript console
	</p>
	<form id="formID" class="formular" method="post" action="phpajax/ajaxValidateSubmit.php" style="width:600px">
		<fieldset>
			<legend>
				Ajax validation
			</legend>
			<label>
				<span>Desired username (ajax validation, only <b>karnius</b> is available) : </span>
				<input value="" class="validate[required,custom[onlyLetterNumber],maxSize[20],ajax[ajaxUserCallPhp]] text-input" type="text" name="user" id="user" />
				<p>
					validate[required,custom[noSpecialCaracters],maxSize[20],ajax[ajaxUserCall]]
				</p>
			</label>
			<label>
				<span>First name (ajax validation, only <b>duncan</b> is available): </span>
				<input value="olivier" class="validate[custom[onlyLetterSp],maxSize[100]] text-input" type="text" name="firstname" id="firstname" />
				<p>
					validate[custom[onlyLetterSp],length[0,100],ajax[ajaxNameCall]]
				</p>
			</label>
			<label>
				<span>Email address : </span>
				<input value="someone1@here.com" class="validate[required,custom[email]] text-input" type="text" name="email" id="email" />
				<p>
					validate[required,custom[email]]
				</p>
			</label>
		</fieldset>
		<input class="submit" type="submit" value="Validate &amp; Send the form!"/><hr/>
	</form>
</body>
</html>